// utils/config.ts
export type EnvType = 'develop' | 'trial' | 'release';

// 环境配置接口
export interface EnvConfig {
  baseUrl: string;
  reportEnabled: boolean;
  debug: boolean;
}

// 各环境具体配置
const configs: Record<EnvType, EnvConfig> = {
  // 开发环境配置
  develop: {
    // baseUrl: 'http://192.168.16.113:8080',
    baseUrl: 'http://192.168.16.197',
    // baseUrl: 'https://rk.vip.cpolar.cn',
    reportEnabled: false,
    debug: true
  },
  
  // 体验环境配置
  trial: {
    baseUrl: 'https://rk.vip.cpolar.cn',
    reportEnabled: true,
    debug: false
  },
  
  // 生产环境配置
  release: {
    baseUrl: 'https://rk.vip.cpolar.cn',
    reportEnabled: true,
    debug: false
  }
};

// 获取当前环境类型
export const getCurrentEnv = (): EnvType => {
  try {
    const accountInfo = wx.getAccountInfoSync();
    const envVersion = accountInfo.miniProgram.envVersion;
    return envVersion as EnvType || 'release';
  } catch (e) {
    // 获取失败时使用 release 环境
    return 'release';
  }
};

// 获取当前环境配置
export const getCurrentConfig = (): EnvConfig => {
  const env = getCurrentEnv();
  return configs[env];
};

// 判断是否为开发环境
export const isDevEnv = (): boolean => {
  return getCurrentEnv() === 'develop';
};

// 获取完整API地址
export const buildApiUrl = (endpoint: string): string => {
  const config = getCurrentConfig();
  return `${config.baseUrl}${endpoint}`;
};

export const appVersion='2.2.0'